#ifndef _CAMCLIENTFRAME_H_
#define _CAMCLIENTFRAME_H_

#include <cv.h>
#include <highgui.h>
#include <wx/frame.h>
#include <wx/scrolwin.h>
#include <wx/button.h>
#include <wx/textctrl.h>
#include <wx/timer.h>
#include <sockclient.h>
#include "videothread.h"
#include "Segmentation.h"

/*!
 * Control identifiers
 */

////@begin control identifiers
#define ID_CAMCLIENTFRAME 10000
#define ID_PANEL 10001
#define ID_LOAD_SESSION 10002
#define ID_TEXTCTRL 10003
#define ID_START_VIDEO_STREAM 10004
#define ID_STOP_VIDEO_STREAM 10005
#define ID_NEW_TRAINING 10006
#define ID_SHOW_THIS_VIDEO 10007
#define ID_LOAD_CONTOUR 10100
#define ID_MAKE_PHOTO 10101
#define SHOW_FRAME_TIMER_ID 20000
#define SHOW_THIS_TIMER_ID 20001
#define SYMBOL_CAMCLIENTFRAME_STYLE wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX
#define SYMBOL_CAMCLIENTFRAME_TITLE _("CamClient")
#define SYMBOL_CAMCLIENTFRAME_IDNAME ID_CAMCLIENTFRAME
#define SYMBOL_CAMCLIENTFRAME_SIZE wxSize(760, 500)
#define SYMBOL_CAMCLIENTFRAME_POSITION wxDefaultPosition
////@end control identifiers


class ContourPanel : public wxScrolledWindow {

	DECLARE_CLASS( ContourPanel )
	DECLARE_EVENT_TABLE()

public:

	ContourPanel(
				wxWindow *parent,
				wxWindowID winid = wxID_ANY,
				const wxPoint& pos = wxDefaultPosition,
				const wxSize& size = wxDefaultSize,
				long style = wxHSCROLL | wxVSCROLL | wxNO_FULL_REPAINT_ON_RESIZE,
				const wxString& name = wxPanelNameStr
	);
	virtual ~ContourPanel();
	void SetBitmap(wxBitmap * bmp);
	void RecalcScrollBars();

protected:
	wxBitmap * bmp;
	void OnPaint(wxPaintEvent & event);
	void OnSize(wxSizeEvent& event);
};


/*!
 * CamClientFrame class declaration
 */


class CamClientFrame: public wxFrame
{    
    DECLARE_CLASS( CamClientFrame )
    DECLARE_EVENT_TABLE()

public:

	wxCriticalSection videoThreadCS;

    CamClientFrame();
    CamClientFrame( wxWindow* parent, wxWindowID id = SYMBOL_CAMCLIENTFRAME_IDNAME, const wxString& caption = SYMBOL_CAMCLIENTFRAME_TITLE, const wxPoint& pos = SYMBOL_CAMCLIENTFRAME_POSITION, const wxSize& size = SYMBOL_CAMCLIENTFRAME_SIZE, long style = SYMBOL_CAMCLIENTFRAME_STYLE );
    bool Create( wxWindow* parent, wxWindowID id = SYMBOL_CAMCLIENTFRAME_IDNAME, const wxString& caption = SYMBOL_CAMCLIENTFRAME_TITLE, const wxPoint& pos = SYMBOL_CAMCLIENTFRAME_POSITION, const wxSize& size = SYMBOL_CAMCLIENTFRAME_SIZE, long style = SYMBOL_CAMCLIENTFRAME_STYLE );
    ~CamClientFrame();
    void Init();
    void CreateControls();
    wxBitmap GetBitmapResource( const wxString& name );
    wxIcon GetIconResource( const wxString& name );
    static bool ShowToolTips();

	void OnThreadCompletion();
	void OnServerDisconnect();

protected:

	ContourPanel * contourPanel;
	wxButton * openContourButton;
	wxButton * openSessionButton;
	wxButton* trainClassificator;
	wxButton* startVideoStream;
	wxButton* stopVideoStream;
	wxButton* showThisVideo;
	wxButton* makePhoto;
	wxTextCtrl* ipAddressText;
	wxTimer videoFrameTimer;
	wxTimer videoThisTimer;
	VideoThread * videoThread;
	IplImage* ConturFr;
	CvCapture * thisCapture;
	IplImage * photo;
	wxFrame * objectsTrainingFrame;


	static const char * videoWindowName;

	void OnOpenContour(wxCommandEvent & event);
	void OnOpenThisCamera(wxCommandEvent & event);
	void OnMakePhoto(wxCommandEvent & event);
	void OnStartVideoStream(wxCommandEvent & event);
	void OnStopVideoStream(wxCommandEvent & event);
	void OnClose(wxCloseEvent & event);
	void OnTimer(wxTimerEvent & event);
	void OnThisTimer(wxTimerEvent & event);

	void OnOpenExistingSession(wxCommandEvent & event);
	void OnNewTraining(wxCommandEvent & event);

	void OnThreadStart();
	void OnThreadStop();
	void ProcessVideoFrame(IplImage * image);
};

#endif // _CAMCLIENTFRAME_H_
